/**
 * Created by XiongXuan on 2018/1/10.
 */
var createCollectionUrl = "http://127.0.0.1:8085/center/collection";
var deleteCollectionUrl = "http://127.0.0.1:8085/center/collection";
var loginUrl = "http://127.0.0.1:8085/login";

function createCollection(obj, span) {
    var projectId = document.getElementById("projectId").innerText;

    $.ajax({
        traditional: true,
        type: "PUT",
        url: createCollectionUrl,
        data: {
            "projectId":projectId
        },
        success: function (result) {
            console.log(result);
            if (result.code == 1) {
                alert(result.msg);
                obj.setAttribute("src", "../img/shouchang2.png");
                span.innerHTML="已收藏";

            }
            else {
                alert(result.msg);

            }
        },
        error: function (xhr) {
            alert("请先登录")
            window.location.href=loginUrl+"?ref="+window.location.href;
        },
        dataType: "json"
    });
}

function deleteCollection(obj, span) {
    var projectId = document.getElementById("projectId").innerText;

    console.log(projectId);

    $.ajax({
        // traditional: true,
        type: "DELETE",
        url: deleteCollectionUrl + "?" + $.param({"projectId":projectId}),
        success: function (result) {
            console.log(result);
            if (result.code == 1) {
                alert(result.msg);
                obj.setAttribute("src", "../img/shouchang1.png");
                span.innerHTML="收藏";
            }
            else {
                alert(result.msg);
            }
        },
        dataType: "json"
    });
}

function deleteCollectionInCenter(projectId) {

    console.log(projectId);

    $.ajax({
        // traditional: true,
        type: "DELETE",
        url: deleteCollectionUrl + "?" + $.param({"projectId":projectId}),
        success: function (result) {

            if (result.code == 1) {
                alert(result.msg);
                window.location.reload();
            }
            else {
                alert(result.msg);
            }
        },
        dataType: "json"
    });
}